<template>
    <view class="pro-body">
		   <view class="container">
		       <view class="sechoice">
		           <uni-data-select v-model="value" :localdata="selectRange" @change="change"   placeholder="请选择仓库"></uni-data-select>
		       </view>
			<uni-icons type="scan" :size="60" @click="scanOrderDe"></uni-icons>
		   </view>
		    <view class="procentainer">
				<view class="prolist">
					<view class="procen-item">
						<i style="background: #ffffff;" />已盘仓位数量:{{trayCount}}
					</view>
					<view class="procen-item">
						<i style="background: #ffffff;" />未盘仓位数量:{{unTrayCount}}
					</view>
				</view>
				<!-- <view class="footerPanel_body">
				    <button @click="" class="centerBtn save" >
				        <i></i>确认上传
				    </button>
				</view> -->
			</view>
			<view class="procentainerlist">
				<uni-table ref="table" :loading="loading" border stripe  emptyText="暂无更多数据" @selection-change="selectionChange">
					<uni-tr>
						<uni-th  align="center" >
							<view class="location">仓位</view>
							</uni-th>
						<uni-th align="center">
							<view class="name">是否完成</view>
						</uni-th>
					</uni-tr>
					<uni-tr v-for="(item, index) in locationList" :key="index">
						<view @click="openDetail(item.flocation)" >
							<uni-td  align="center"   >
								<view class="locationValue">{{ item.flocation }}</view>
							</uni-td>

						</view>
						<uni-td align="center" >
							<view class="locationName">
							<uni-tag :text="item.fstatus == 1 ? '已完成' : '未完成'"
							:type="item.fstatus == 1 ? 'success' : 'warning'"></uni-tag>
							</view>
						</uni-td>
						
					</uni-tr>
				</uni-table>
			</view>	
				<!--  底部按钮 -->
				<view class="footerPanel">
					<view class="footerPanel_body">
						<button @click="scanLocationNo" class="footerBtn scan" type="primary"><i class="iconfont icon-saomiao btn_icon"></i>扫描仓位
						</button>
					</view>
				</view>
			</view>
		   
</template>

<script>
import uniIcons from '../../uni_modules/uni-icons/components/uni-icons/icons.js';
import wechat from 'weixin-js-sdk'
import {getOrgList,
getWarehouseList,
wxInit,
getLocationByStock,
getIsBlind} from '@/utils/api.js'
export default {
    data() {
        return {
            loading: false,
			FPRDORGID : 0,
			FPRDORGNAME : '',
			trayCount : 0,//已盘仓位数量
			unTrayCount :0,//未盘仓位数量
			selectRange : [],
			wechat:{},
			isBlind:false,//false 明盘 true:盲盘
			value : '',//仓库编码
			stockName : '',//仓库名称
            locationList: []//仓位列表
        };
    },
	
    methods: {
		scanOrderDe(){
			wechat.scanQRCode({
				needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果
				scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
				success: (res) => {
				  // 当needResult 为 1 时，扫码返回的结果
		        this.change(res.resultStr)
				 //扫码成功后切换仓库
				 
				}
			 });
		},
		/**
		 * 扫描仓位
		 */
		scanLocationNo(){
			wechat.scanQRCode({
				needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果
				scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
				success: (res) => {
				  // 当needResult 为 1 时，扫码返回的结果
				 //res.resultStr
				//扫描仓位后直接跳转到详情
				this.openDetail(res.resultStr)
				}
			 });
		},
		//获取微信配置信息
		getWxConfig(url){
			wxInit({'url' :url }).then(res =>{
				this.saveWxConfig(res.data.data)
			})
		},
		//配置微信config
		saveWxConfig(res){
			// 配置config信息
			wechat.config({
				debug: false,
				appId: res.appid, // 必填，公众号的唯一标识
				timestamp: res.timestamp, // 必填，生成签名的时间戳
				nonceStr: res.nonceStr, // 必填，生成签名的随机串
				signature: res.signature, // 必填，签名
				jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表
			});
		
			// 通过ready接口处理成功验证
			wechat.ready(function () {
				wechat.checkJsApi({
					jsApiList: ['scanQRCode'],
					success: function (res) {
						//console.log('检验成功');
					}
				});
			});
			// 通过error接口处理失败验证
			wechat.error(function (res) {
				//console.log('校验失败');
			});
		
		},
	
		/**
		 * 查看仓位盘点情况
		 */
		openDetail(e){
			let self = this
			if (this.isBlind){//盲盘
				uni.navigateTo({
					url:'/pages/Stock/MangStocktaking?FPRDORGID=' + self.FPRDORGID + '&stockNo=' 
					+ self.value + '&locationNo=' + e + '&stockName=' + self.stockName,
				})
			} else{//明盘
				uni.navigateTo({
					url:'/pages/Stock/MingStocktaking?FPRDORGID=' + self.FPRDORGID + '&stockNo='
					 + self.value + '&locationNo=' + e+ '&stockName=' + self.stockName,
				})
			}
		},
		//修改仓库后
		change(e){
			this.value = e
		
			for(let i =0;i < this.selectRange.length;i++){
				if (this.selectRange[i].value == e){
					this.stockName = this.selectRange[i].text
				}
			}
			this.getLocationByStock()
		},
		initData (){
			this.getIsBlind()
			this.getWarehouseList()
		},
		/**
		 * 判断仓库是明盘还是盲盘
		 */
		getIsBlind(){
			getIsBlind({FOrgId : this.FPRDORGID}).then(res => {
				this.isBlind = res.data.data.res
			})
		},
		/**
		 * 根据仓库和组织获取仓位信息
		 */
		getLocationByStock(){
			getLocationByStock({FOrgId : this.FPRDORGID,FStockId : this.value}).then(res => {
				this.locationList = res.data.data.dataList
				this.unTrayCount = res.data.data.fstatus0
				this.trayCount = res.data.data.fstatus1
				
			})
		},
        selectionChange(selection) {
            //console.log('Selection changed:', selection);
        },
		
		//获取仓库列表
		getWarehouseList(){
			getWarehouseList({FOrgId : this.FPRDORGID,FOrgName : this.FPRDORGNAME}).then(res => {
				this.selectRange = res.data.data
				this.value = res.data.data[0].value
				this.stockName= res.data.data[0].text
				this.getLocationByStock()
			})
		},
    },
	
	onLoad(e){
		this.FPRDORGID = e.FPRDORGID
		this.FPRDORGNAME = e.FPRDORGNAME
		
		//刷新数据
		this.initData()
		if (typeof window.entryUrl === 'undefined' || window.entryUrl === ""){
		  	window.entryUrl = location.href.split('#')[0]
		  }
		  let url = /Android/i.test(navigator.userAgent)
		    ? window.location.href
		    : window.entryUrl
		this.getWxConfig(url)
		
	},
	mounted() {
		let self = this
		uni.$on('update',function(date){
			self.initData()
		})
	},
	onUnload() {
		//移除监听事件
		uni.$off('update')
	}
};
</script>

<style lang="scss" scoped>
	@import "../../static/css/common";
	/* #endif */
	.pro-body{
		background-color: #ffffff;
	}
	.promenu-item {
	         display: flex;
	         align-items: center;
	         justify-content: center;
	         height: 40px;
			 font-size: 26px; /* 增大字体大小 */
			 // font-weight: bold; /* 加粗字体 */
			 border-bottom: 2px solid #c1c1c1; /* 添加水平分割线 */
	    }
		.container {
		    display: flex;
		    align-items: center; /* 垂直居中对齐 */
		    justify-content: space-between; /* 水平均匀分布 */
		}

	.sechoice {//调整下拉列表框
	    width: 300px;
	    height: 40px;
	    display: flex;
	    align-items: center;
	    justify-content: center;
		padding: 15px;

	}
	
	.sechoice uni-data-select {
	    width: 100%;
	    height: 100%;
	    display: flex;
	    align-items: center;
	    justify-content: center;
	}
	
	.sechoice uni-data-select .uni-select {
	    width: 100%;
	    height: 100%;
	    display: flex;
	    align-items: center;
	    justify-content: center;

	}
	
	.sechoice uni-data-select .uni-select__input {
	    width: 100%;
	    height: 100%;
	    display: flex;
	    align-items: center;
	    justify-content: center;
	}
	.procentainer {
	    display: flex;
	    align-items: center; /* 垂直居中对齐 */
	    justify-content: space-between; /* 水平均匀分布 */
	    padding: 10px; /* 添加一些内边距 */
	}
	.procen-item {
	        margin-bottom: 10px; /* 增加间距 */
	}
	.footerPanel_body {//提交按钮
		display: flex;
		align-items: center;
	}
	.centerBtn {
		width: 140px; /* 调整按钮宽度 */
		height: 50px; /* 调整按钮高度 */
		 font-size: 18px; /* 增大字体大小 */
		background-color:  #9dec00;
		display: flex;
		align-items: center;
		justify-content: center;
		 border-radius: 0; /* 移除圆角 */
	}


/* 表格中的文本样式 */

	.name {
		
		font-size: 18px;
		color: #000000;
	}
	.location {
		
		font-size: 18px;
		color: #000000;
	}
	.locationValue{
		width:150px;
		font-size: 18px;
		color: #000000;
	}
	.locationName{
		width:150px;
		font-size: 18px;
		color: #000000;
	}
</style>